package com.zzyl.mapper;

import cn.hutool.core.date.DateTime;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.zzyl.entity.Reservation;
import com.zzyl.vo.TimeCountVo;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.time.LocalDateTime;
import java.util.List;

@Mapper
public interface ReservationMapper extends BaseMapper<Reservation> {
    @Select("select count(*) from app_reservation where update_time between #{begin} and #{end} and status = 2 and update_by = #{userId}")
    Integer getCancelledCount(DateTime begin, DateTime end, Long userId);

    @Select("SELECT time, 6 - COUNT(*) AS count FROM app_reservation where time between #{begin} and #{end} and status != 2 group by time")
    List<TimeCountVo> getRemainingCount(LocalDateTime begin, LocalDateTime end);
}
